#include<bits/stdc++.h>
using namespace std;

int t,n,m,l,vmax;
int d[100005],v[100005],a[100005],p[100005];
vector< pair<int,int> > pp;
int dm=0,ans;

bool judge(int din,int vin,int ain){
    if(din>p[m])return 0;
    int dii=1;while(p[dii]<din) dii++;
    if(ain==0){
        if(vin>vmax){pp.push_back(make_pair(dii,m));return true;}
        else return 0;
    }
    else if(ain<0){
        if(vin<=vmax)return 0;
        dm=(((1ll*vmax*vmax)-(1ll*vin*vin))/(2*ain)+din);
        if(dm<p[dii])return 0;
        int dmax;dmax=(upper_bound(p+1,p+1+m,dm)-p)-1;
        pp.push_back(make_pair(dii,dmax));
        return 1;
    }
    else {
        if(vin>vmax){pp.push_back(make_pair(dii,m));return 1;}
        dm=(1ll*vmax*vmax-1ll*vin*vin)/(2*ain)+1+din;
        if(dm>p[m])return 0;
        int dmin=lower_bound(p+1,p+1+m,dm)-p;
        pp.push_back(make_pair(dmin,m));
        return 1;
    }
}

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        ans=0;
        cin>>n>>m>>l>>vmax;
        memset(d,0,sizeof(d));
        memset(v,0,sizeof(v));
        memset(a,0,sizeof(a));
        memset(p,0,sizeof(p));
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++)cin>>p[i];
        sort(p+1,p+1+m);
        for(int i=1;i<=n;i++){
            if(judge(d[i],v[i],a[i]))ans++;
        }
        cout<<ans<<" "<<m-1<<endl;
    }
    return 0;
}
